home *** CD-ROM | disk | FTP | other *** search
- unit Joystick;
- interface
- uses CRT;
-
- { Joystick interface for Turbo Pascal V. 4.0 and above
- Public Domain, November 1989 by
- JonSoft Technologies Inc.
- (C) 1989 JonSoft Technologies Inc. }
-
- const
- CentX : byte=80;
- CentY : byte=40;
- Joyst : boolean=true;
-
- procedure FastInitJS;
- procedure BetterInitJS( Range : byte );
- function JoyX : byte;
- function JoyY : byte;
- function Button1 : byte;
- function Button2 : byte;
- function Horiz : shortint;
- function Vert : shortint;
-
-
- implementation
-
- const
- RangeXM : byte=25;
- RangeYM : byte=20;
- RangeXP : byte=25;
- RangeYP : byte=25;
-
- function JoyX : byte;
- var
- X : word;
- begin
- X:=0;
- Port[$201]:=$ff;
- While Port[$201] and $1=1 do Inc(X);
- JoyX:=X;
- end;
-
- function JoyY : byte;
- var
- Y : word;
- begin
- Y:=0;
- Port[$201]:=$0;
- While Port[$201] and $2=2 do Inc(Y);
- JoyY:=Y;
- end;
-
- procedure FastInitJs;
- begin
- CentX:=JoyX;
- CentY:=JoyY;
- end;
-
- function Button1 : byte;
- begin
- Button1:=((Port[$201] and $10) xor $10) shr 4;
- end;
-
- function Button2 : byte;
- begin
- Button2:=((Port[$201] and $20) xor $20) shr 5;
- end;
-
- procedure BetterInitJs(Range : byte);
- var
- ch : char;
- UprJoyX, UprJoyY, CentrJoyX, CentrJoyY, LowrJoyX, LowrJoyY : byte;
-
- begin
- writeln('Are you using a joystick? (Button = yes, RETURN = no)');
- Repeat
- If Button1+Button2>0 then Joyst:=true;
- If Keypressed then Joyst:=false;
- Until (Button1+Button2>0) or Keypressed;
- If Joyst=true then begin
- repeat until Button1+Button2=0;
- Writeln('Move joystick to UPPER RIGHT corner and press a button.');
- repeat until Button1+Button2>0;
- UprJoyX:=JoyX;
- UprJoyY:=JoyY;
- repeat until Button1+Button2=0;
- Writeln('Move joystick to CENTER and press a button.');
- repeat until Button1+Button2>0;
- CentrJoyX:=JoyX;
- CentrJoyY:=JoyY;
- CentX:=CentrJoyX;
- CentY:=CentrJoyY;
- repeat until Button1+Button2=0;
- Writeln('Move joystick to LOWER LEFT CORNER and press a button.');
- repeat until Button1+Button2>0;
- LowrJoyX:=JoyX;
- LowrJoyY:=JoyY;
- RangeXM:=(CentrJoyX-UprJoyX) div Range;
- RangeXP:=(LowrJoyX-CentrJoyX) div Range;
- RangeYM:=(CentrJoyY-UprJoyY) div Range;
- RangeYP:=(LowrJoyY-CentrJoyY) div Range;
- end;
- end;
-
- function Horiz : shortint;
- begin
- If JoyX<CentX-RangeXM then Horiz:=-1
- else if JoyX>CentX+RangeXP then Horiz:=1
- else Horiz:=0;
- end;
-
- function Vert : shortint;
- begin
- If JoyY<CentY-RangeYM then Vert:=-1
- else if JoyY>CentY+RangeYP then Vert:=1
- else Vert:=0;
- end;
- end.